package cn.stylefeng.guns.modular.fruits.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.fruits.entity.FruitsOrderPut;
import cn.stylefeng.guns.modular.fruits.mapper.FruitsOrderPutMapper;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsOrderPutParam;
import cn.stylefeng.guns.modular.fruits.model.result.FruitsOrderPutResult;
import  cn.stylefeng.guns.modular.fruits.service.FruitsOrderPutService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 采摘入库管理 服务实现类
 */
@Service
public class FruitsOrderPutServiceImpl extends ServiceImpl<FruitsOrderPutMapper, FruitsOrderPut> implements FruitsOrderPutService {

    @Override
    public void add(FruitsOrderPutParam param){
        FruitsOrderPut entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FruitsOrderPutParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FruitsOrderPutParam param){
        FruitsOrderPut oldEntity = getOldEntity(param);
        FruitsOrderPut newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FruitsOrderPutResult findBySpec(FruitsOrderPutParam param){
        return null;
    }

    @Override
    public List<FruitsOrderPutResult> findListBySpec(FruitsOrderPutParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FruitsOrderPutParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findAnalysisPageBySpecApplets(FruitsOrderPutParam param,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findAnalysisPageBySpecApplets(pageContext, param, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findAnalysisPageBySpec(FruitsOrderPutParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findAnalysisPageBySpec(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findWorkertaskPageBySpec(FruitsOrderPutParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findWorkertaskPageBySpec(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findJiagongcangPagelist(FruitsOrderPutParam param,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findJiagongcangPagelist(pageContext, param, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findzhifacangPagelist(FruitsOrderPutParam param,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findzhifacangPagelist(pageContext, param, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FruitsOrderPutParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FruitsOrderPut getOldEntity(FruitsOrderPutParam param) {
        return this.getById(getKey(param));
    }

    private FruitsOrderPut getEntity(FruitsOrderPutParam param) {
        FruitsOrderPut entity = new FruitsOrderPut();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public int countBydate(FruitsOrderPutParam to,Long operateId) {
		Integer a;
		a = this.baseMapper.countBydate(to,operateId);
		if (a == null) {
			return 0;
		}
		return a;
	}

}
